# Install and load packages
library(tidyverse)
library(readxl)
library(ggstream)
library(showtext)
library(ggtext)
install.packages("viridis")
library("viridis")

# Load dataset
emissions <- read.csv("percentagecarbonemissions_13autocracies.csv",header = TRUE)

# Color palette 
pal <- viridis(n = 13, option = "B" )

# Stacking order
order <- c("China","Russia","Iran","Saudi Arabia","Vietnam","United Arab Emirates","Iraq","Uzbekistan","Venezuela",
           "Turkmenistan","Oman","Belarus","Azerbaijan")

# Plot
emissions %>% 
  arrange(Percentage) %>%
  mutate(Country = factor(Country, levels=order)) %>% 
  ggplot(aes(Year, Percentage, fill = Country, label = Country, color = Country)) +
  geom_area() +
  scale_fill_manual(values=pal) +
  scale_color_manual(values=pal) +
  scale_x_continuous(breaks=c(2000,2005,2010,2015,2020),labels = c("2000","2005","2010","2015","2020")) +
  scale_y_continuous(expand=c(0,0),limits=c(0,50),breaks=c(10,20,30,40,50),labels = c("10","20","30","40","50")) +
  coord_cartesian(clip = "off") +
  xlab("Year") + ylab("Contribution to Global Carbon Emissions (%)")
